import { 
  Controller, 
  Get, 
  Post, 
  Body, 
  Patch, 
  Param, 
  Delete,
  Query
} from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse, ApiBody, ApiParam, ApiQuery } from '@nestjs/swagger';
import { JobsService } from './jobs.service';
import { CreateJobDto } from './dto/create-job.dto';
import { UpdateJobDto } from './dto/update-job.dto';
import { Job, JobStatus } from './entities/job.entity';

@ApiTags('jobs')
@Controller('jobs')
export class JobsController {
  constructor(private readonly jobsService: JobsService) {}

  @Post()
  @ApiOperation({ summary: '创建任务' })
  @ApiBody({ type: CreateJobDto })
  @ApiResponse({ status: 201, description: '任务创建成功', type: Job })
  @ApiResponse({ status: 400, description: '请求参数错误' })
  async create(@Body() createJobDto: CreateJobDto): Promise<Job> {
    return await this.jobsService.create(createJobDto);
  }

  @Get()
  @ApiOperation({ summary: '获取所有任务' })
  @ApiResponse({ status: 200, description: '获取成功', type: [Job] })
  async findAll(): Promise<Job[]> {
    return await this.jobsService.findAll();
  }

  @Get('status/:status')
  @ApiOperation({ summary: '根据状态获取任务' })
  @ApiParam({ name: 'status', enum: JobStatus, description: '任务状态' })
  @ApiResponse({ status: 200, description: '获取成功', type: [Job] })
  async findByStatus(@Param('status') status: JobStatus): Promise<Job[]> {
    return await this.jobsService.findByStatus(status);
  }

  @Get('category/:category')
  @ApiOperation({ summary: '根据分类获取任务' })
  @ApiParam({ name: 'category', description: '任务分类' })
  @ApiResponse({ status: 200, description: '获取成功', type: [Job] })
  async findByCategory(@Param('category') category: string): Promise<Job[]> {
    return await this.jobsService.findByCategory(category);
  }

  @Get('wallet/:walletAddress')
  @ApiOperation({ summary: '根据钱包地址获取任务' })
  @ApiParam({ name: 'walletAddress', description: '钱包地址' })
  @ApiResponse({ status: 200, description: '获取成功', type: [Job] })
  async findByWalletAddress(@Param('walletAddress') walletAddress: string): Promise<Job[]> {
    return await this.jobsService.findByWalletAddress(walletAddress);
  }

  @Get(':id')
  @ApiOperation({ summary: '根据ID获取任务' })
  @ApiParam({ name: 'id', description: '任务ID' })
  @ApiResponse({ status: 200, description: '获取成功', type: Job })
  @ApiResponse({ status: 404, description: '任务不存在' })
  async findOne(@Param('id') id: string): Promise<Job> {
    return await this.jobsService.findOne(id);
  }

  @Patch(':id')
  @ApiOperation({ summary: '更新任务' })
  @ApiParam({ name: 'id', description: '任务ID' })
  @ApiBody({ type: UpdateJobDto })
  @ApiResponse({ status: 200, description: '更新成功', type: Job })
  @ApiResponse({ status: 404, description: '任务不存在' })
  async update(@Param('id') id: string, @Body() updateJobDto: UpdateJobDto): Promise<Job> {
    return await this.jobsService.update(id, updateJobDto);
  }

  @Delete(':id')
  @ApiOperation({ summary: '删除任务' })
  @ApiParam({ name: 'id', description: '任务ID' })
  @ApiResponse({ status: 200, description: '删除成功' })
  @ApiResponse({ status: 404, description: '任务不存在' })
  async remove(@Param('id') id: string): Promise<void> {
    return await this.jobsService.remove(id);
  }
} 